package com.tan.cloud_8001.Controller;



import com.api.cloud_api.Entity.CommonResult;
import com.api.cloud_api.Entity.Pay;
import com.tan.cloud_8001.Service.PayService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 */
@RestController
@Slf4j
public class PayController{
    @Resource
    private PayService payService;

    @Value("${server.port}")
    private String serverport;

    @PostMapping(value = "/Pay/create")
    public CommonResult create(@RequestBody Pay payment)
    {
        Long result = payService.create(payment);
        log.info("*****插入结果："+result);

        if(result > 0)
        {
            return new CommonResult(200,"插入数据库成功,serverPort: "+serverport,result);
        }else{
            return new CommonResult(444,"插入数据库失败",null);
        }
    }
    @GetMapping(value = "Pay/get/{id}")
    public CommonResult<Pay> getPaymentById(@PathVariable("id") Long id)
    {
        Pay payment = payService.getPaymentById(id);

        if(payment != null)
        {
            return new CommonResult(200,"查询成功,serverPort: "+serverport,payment);
        }else{
            return new CommonResult(444,"没有对应记录,查询ID: "+id,null);
        }
    }
    @GetMapping(value = "/get/sleep")
    public String getsleep(){
        try {
            TimeUnit.SECONDS.sleep(3);
        }catch (Exception e) {
        e.printStackTrace();
        }
        return serverport;
    }
}


